package com.owc.controller.app;

import com.owc.domain.BaseResult;
import com.owc.domain.dto.*;
import com.owc.domain.vo.app.FlowVo;
import com.owc.domain.vo.app.TokenDetailVo;
import com.owc.domain.vo.app.TokenVo;
import com.owc.domain.vo.app.TransferVo;
import com.owc.service.app.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.math.BigDecimal;
import java.util.List;

/**
 * @Author Jackies
 * @Date 2019/12/3 22:32
 * @Description TODO://
 **/
@RestController
@RequestMapping("/wallet")
@Api(tags = "(APP-V1)钱包首页")
public class WalletController {

    @Autowired
    private WalletService walletService;

    /**
     * 获取用户代币列表信息
     */
    @PostMapping(value = "/getTokenList")
    @ApiOperation("获取用户代币列表信息")
    public BaseResult<List<TokenInfo>> getTokenList(){
        return BaseResult.success(walletService.getTokenList());
    }

    /**
     * 获取代币详情
     */
    @PostMapping(value = "/tokenDetail")
    @ApiOperation("获取代币详情")
    public BaseResult<TokenDetail> tokenDetail(@RequestBody @Valid TokenDetailVo tokenDetailVo){
        return walletService.getTokenDetailList(tokenDetailVo);
    }

    /**
     * 转账
     */
    @PostMapping(value = "/transfer")
    @ApiOperation("发起转账")
    public BaseResult<Boolean> transfer(@RequestBody @Valid TransferVo transferVo) throws Exception {
        return BaseResult.success(walletService.transfer(transferVo));
    }

    /**
     * 获取代币余额
     */
    @PostMapping(value = "/getTokenBalance")
    @ApiOperation("获取用户代币余额")
    public BaseResult<BalanceDTO> getTokenBalance(@RequestBody @Valid TokenVo tokenVo){
        return BaseResult.success(walletService.getTokenBalance(tokenVo.getTokenId()));
    }

    /**
     * 获取钱包地址  根据tokenId
     */
    @PostMapping(value = "/getTokenAddress")
    @ApiOperation("获取用户钱包地址")
    public BaseResult<TokenAddress> getTokenAddress(@RequestBody @Valid TokenVo tokenVo){
        return BaseResult.success(walletService.getTokenAddress(tokenVo.getTokenId()));
    }

    /**
     * 获取代币手续费
     */
    @PostMapping(value = "/getTokenHandlingFee")
    @ApiOperation("获取代币手续费")
    public BaseResult<TokenHandlingFee> getTokenHandlingFee(@RequestBody @Valid TokenVo tokenVo){
        return BaseResult.success(walletService.getTokenHandlingFee(tokenVo.getTokenId()));
    }

    /**
     * 获取流水详情
     */
    @PostMapping(value = "/getFlowDetail")
    @ApiOperation("获取流水详情")
    public BaseResult<FlowDetail> getFlowDetail(@RequestBody @Valid FlowVo flowVo){
        return BaseResult.success(walletService.getFlowDetail(flowVo.getTransferId()));
    }

    @PostMapping(value = "/getUserIncomeInfo")
    @ApiOperation("APP(V2) 获取用户收益情况")
    public BaseResult<UserIncome> getUserIncomeInfo(){
        return BaseResult.success(walletService.getUserIncomeInfo());
    }



}
